# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=openal
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.17.2
pkgrel=4
pkgdesc="OpenAL audio library for use with opengl (mingw-w64)"
arch=('any')
url="http://kcat.strangesoft.net/openal.html"
license=('GPL2')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-fluidsynth"
             "${MINGW_PACKAGE_PREFIX}-portaudio")
options=('strip' 'staticlibs')
source=(http://kcat.strangesoft.net/openal-releases/openal-soft-${pkgver}.tar.bz2
        0001-versioned-w32-dll.mingw.patch
        0002-w32ize-portaudio-loading.mingw.patch
        0003-openal-not-32.mingw.patch
        0004-disable-OSS-windows.patch)
sha256sums=('a341f8542f1f0b8c65241a17da13d073f18ec06658e1a1606a8ecc8bbc2b3314'
            'a4ff8f8333bb19a933c2f137a49a2efe62931325100aef3eb21fdbb1ca899e5e'
            'c97ebc76c1063249a61ae9843405071feb54fae4ef8cba17e82da924f09273a0'
            'cde8cf4045730055ea7ccfe0a8477b73d7be0f08aea3ac3dedf47e76532928a3'
            'aa6fc2efb76424d0337d609f3002abb8ff179ed15ae633c53433bcb176e643ba')

prepare() {
  cd openal-soft-${pkgver}
  patch -p1 -i ${srcdir}/0001-versioned-w32-dll.mingw.patch
  patch -p1 -i ${srcdir}/0002-w32ize-portaudio-loading.mingw.patch
  patch -p1 -i ${srcdir}/0003-openal-not-32.mingw.patch
  patch -p1 -i ${srcdir}/0004-disable-OSS-windows.patch
}

build() {
  export DXSDK_DIR=${MINGW_PREFIX}/${MINGW_CHOST}
  mkdir -p "${srcdir}/build-shared-${MINGW_CHOST}" && cd "${srcdir}/build-shared-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DALSOFT_EXAMPLES=OFF \
    -DLIBTYPE=SHARED \
    -DDSOUND_INCLUDE_DIR=${MINGW_PREFIX}/${MINGW_CHOST}/include \
    -DDSOUND_LIBRARY=${MINGW_PREFIX}/${MINGW_CHOST}/lib/libdsound.a \
    ../openal-soft-${pkgver}
  make

  mkdir -p "${srcdir}/build-static-${MINGW_CHOST}" && cd "${srcdir}/build-static-${MINGW_CHOST}"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DALSOFT_EXAMPLES=OFF \
    -DLIBTYPE=STATIC \
    -DDSOUND_INCLUDE_DIR=${MINGW_PREFIX}/${MINGW_CHOST}/include \
    -DDSOUND_LIBRARY=${MINGW_PREFIX}/${MINGW_CHOST}/lib/libdsound.a \
    ../openal-soft-${pkgver}
  make
}

package() {
  cd "${srcdir}/build-static-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  cd "${srcdir}/build-shared-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
